cmake_minimum_required(VERSION 3.16)

project(bootloader_pc VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

unset(EN_UNITTEST CACHE)
option(EN_UNITTEST "Enable unit tests" ON)

set(CAN_LIB_DIR ${PROJECT_SOURCE_DIR}/thirty_lib/ControlCAN)
set(CAN_LIBRARY ${CAN_LIB_DIR}/lib/x64/ControlCAN.dll)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets SerialPort)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets SerialPort)
# Check if required file exists
if (NOT EXISTS "${CAN_LIB_DIR}/lib/x64/ControlCAN.dll")
    message(FATAL_ERROR "${CAN_LIB_DIR}/lib/x64/ControlCAN.dll file exists")
endif()


include_directories(${PROJECT_SOURCE_DIR})
include_directories(src)
include_directories(${CAN_LIB_DIR}/inc)

# file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}" NATIVE_PROJECT_PATH)
add_definitions(-DPROJECT_ROOT_DIR="${CMAKE_SOURCE_DIR}")

add_subdirectory(src)
if (EN_UNITTEST)
    add_subdirectory(test)
endif()
